package com.heima.Control;

import com.heima.anno.LogAnno;
import com.heima.poji.Dept;
import com.heima.poji.Emp;
import com.heima.poji.Result;
import com.heima.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@RestController
@RequestMapping("/depts")
public class DepContral {
    @Autowired
    private DeptService deptService;
    @GetMapping
    public Result list(){
        log.info("输出全部员工信息");
        List<Dept> li=deptService.list();
        return Result.success(li);
    }

    //根据id删除数据
    @DeleteMapping("{id}")
    public Result delectById(@PathVariable Integer id){//注解获取id的作用
        deptService.delectById(id);
        log.info("删除部门表数据{}",id);
        return Result.success();
    }

    //新增部门信息
    @PostMapping
    public Result add(@RequestBody Dept dept){
        deptService.add(dept);
        return Result.success();
    }



    @GetMapping("/{id}")
    public Result selectByid( @PathVariable Integer id){
        Dept d= deptService.selectByid(id);
        return  Result.success(d);
    }


    @LogAnno
    //部门修改
    @PutMapping
    public Result update(@RequestBody Dept dept){
        log.info("输出部门信息{}",dept);
        deptService.update(dept);
        return Result.success();
    }
    @PutMapping("/date")
    public Result update( ){
        log.info("hello");
        return Result.success();
    }
}
